package com.yida.wy.basic.controller;

import com.mybatisflex.core.paginate.Page;
import com.yida.common.core.web.domain.AjaxResult;
import com.yida.common.core.web.page.TableDataInfo;
import com.yida.wy.basic.domain.WyBasePartyOrganizationStaff;
import com.yida.wy.basic.service.IWyBasePartyOrganizationStaffService;
import com.yida.wy.common.web.controller.BaseController;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.io.Serializable;

/**
 * 党员基础信息 控制层。
 *
 * @author lqq
 * @since 1.0
 */
@RestController
@RequestMapping("/wyBasePartyOrganizationStaff")
@Api(tags = "党员基础信息")
public class WyBasePartyOrganizationStaffController extends BaseController {

    @Autowired
    private IWyBasePartyOrganizationStaffService wyBasePartyOrganizationStaffService;

    /**
     * 添加 党员基础信息
     *
     * @param wyBasePartyOrganizationStaff 党员基础信息
     * @return {@code true} 添加成功，{@code false} 添加失败
     */
    @PostMapping("/save")
    @ApiOperation(value = "添加党员基础信息", notes = "添加党员基础信息")
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "partyOrganizationStaffId", value = "党组织人员名单"),
            @ApiImplicitParam(name = "partyOrganizationId", value = "党组织ID"),
            @ApiImplicitParam(name = "staffName", value = "人员名单"),
            @ApiImplicitParam(name = "contactPhone", value = "联系人电话号码"),
            @ApiImplicitParam(name = "staffPost", value = "人员职位"),
            @ApiImplicitParam(name = "partyType", value = "0:预备党员;1:正式党员"),
            @ApiImplicitParam(name = "avatarFileCode", value = "头像文件编码")})
    public AjaxResult save(@RequestBody WyBasePartyOrganizationStaff wyBasePartyOrganizationStaff) {
        return toAjax(wyBasePartyOrganizationStaffService.save(wyBasePartyOrganizationStaff));
    }


    /**
     * 根据主键删除党员基础信息
     *
     * @param id 主键
     * @return {@code true} 删除成功，{@code false} 删除失败
     */
    @DeleteMapping("/remove/{id}")
    @ApiOperation(value = "根据主键删除党员基础信息", notes = "根据主键删除党员基础信息")
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "partyOrganizationStaffId", value = "党组织人员名单", required = true)
    })
    public AjaxResult remove(@PathVariable Serializable id) {
        return toAjax(wyBasePartyOrganizationStaffService.removeById(id));
    }


    /**
     * 根据主键更新党员基础信息
     *
     * @param wyBasePartyOrganizationStaff 党员基础信息
     * @return {@code true} 更新成功，{@code false} 更新失败
     */
    @PutMapping("/update")
    @ApiOperation(value = "根据主键更新党员基础信息", notes = "根据主键更新党员基础信息")
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "partyOrganizationStaffId", value = "党组织人员名单", required = true),
            @ApiImplicitParam(name = "partyOrganizationId", value = "党组织ID"),
            @ApiImplicitParam(name = "staffName", value = "人员名单"),
            @ApiImplicitParam(name = "contactPhone", value = "联系人电话号码"),
            @ApiImplicitParam(name = "staffPost", value = "人员职位"),
            @ApiImplicitParam(name = "partyType", value = "0:预备党员;1:正式党员"),
            @ApiImplicitParam(name = "avatarFileCode", value = "头像文件编码")})
    public AjaxResult update(@RequestBody WyBasePartyOrganizationStaff wyBasePartyOrganizationStaff) {
        return toAjax(wyBasePartyOrganizationStaffService.updateById(wyBasePartyOrganizationStaff));
    }


    /**
     * 查询所有党员基础信息
     *
     * @return 所有数据
     */
    @GetMapping("/list")
    @ApiOperation(value = "查询所有党员基础信息", notes = "查询所有党员基础信息")
    public AjaxResult list() {
        return AjaxResult.success(wyBasePartyOrganizationStaffService.list());
    }


    /**
     * 根据党员基础信息主键获取详细信息。
     *
     * @param id wyBasePartyOrganizationStaff主键
     * @return 党员基础信息详情
     */
    @GetMapping("/getInfo/{id}")
    @ApiOperation(value = "根据党员基础信息主键获取详细信息", notes = "根据党员基础信息主键获取详细信息")
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "partyOrganizationStaffId", value = "党组织人员名单", required = true)
    })
    public AjaxResult getInfo(@PathVariable Serializable id) {
        return AjaxResult.success(wyBasePartyOrganizationStaffService.getById(id));
    }


    /**
     * 分页查询党员基础信息
     *
     * @param page 分页对象
     * @return 分页对象
     */
    @GetMapping("/page")
    @ApiOperation(value = "分页查询党员基础信息", notes = "分页查询党员基础信息")
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "pageNum", value = "页码", required = true),
            @ApiImplicitParam(name = "pageSize", value = "每页大小", required = true)
    })
    public TableDataInfo page(Page<WyBasePartyOrganizationStaff> page) {
        return getDataTable(wyBasePartyOrganizationStaffService.page(page));
    }
}